#ifndef __ZHTTP_H_
	#define __ZHTTP_H_

#ifndef BUFFSIZE
	#define BUFFSIZE 4096
#endif
#ifndef RECEIVE_BUFFSIZE
	#define RECEIVE_BUFFSIZE 1024*1024*8
#endif
#ifndef FIELD_SIZE
	#define FIELD_SIZE 25
#endif
#ifndef MAX_POST_SIZE
	#define MAX_POST_SIZE 2*1024*1024
#endif
#ifndef MAX_HOST_SIZE
	#define MAX_HOST_SIZE 1024
#endif
#ifndef MAX_PROTOCOL_SIZE
	#define MAX_PROTOCOL_SIZE 12
#endif
#ifndef MAX_URI_SIZE
	#define MAX_URI_SIZE 1024
#endif

#ifndef PORT
	#define PORT 80
#endif
#ifndef HTTP_EDITION
	#define HTTP_EDITION "HTTP/1.1"
#endif
#ifndef ACCEPT
	#define ACCEPT "*/*"
#endif
#ifndef CONNECTION
	#define CONNECTION "Keep-alive"
#endif
#ifndef DEFAULT_HTTP_HEADERS
	#define DEFAULT_HTTP_HEADERS "Content-Type: application/x-www-form-urlencoded\r\n"
#endif

/*Structure declaration and difinition*/
struct field{
	char * key;
	char * value;
};
typedef struct field kv;

struct http_header{
	char * method;//support GET POST HEADER
	char * uri;//not include host name
	char * protocol;
	char * host;//support host name and ip
	struct field * params;//http request headers
	int c;//param number
	struct field * data;//GET and POST data
	int d;//data number
};
typedef struct http_header http_header;

/*Function declarations*/
void Die(char *mess);
/*Parse struct field type to url like &key=value*/
char * data2url(struct field * data, int d,int size);
/*Create a new http request header structure*/
struct http_header * new_http_header(
	char * method,
	char * uri,
	char * protocol,
	char * host,
	struct field params[],
	int c,
	struct field data[],
	int d);
/*Create a HTTP request header C-style string*/
char * new_http_header_str(struct http_header * header);
/*Parse host to ip*/
char * nslkup(const char * host_name);
/*Send data to any port on a host*/
char * send_to(const char * host, int port,const char * data);
/*Send a GET or POST http request to server on port 80*/
char * http_request(
	const char * method,
	const char * host,
	const char * uri,
	const char * http_edition,
	struct field * params,
	int n,
	struct field * data,
	int m,
	int echo);//0: echo off 1: echo on
char * filte_http_response_header(char * rps);
char * filte_html_from(char * receive);
char * zurl(const char * uri,char * opt);
/*
static const char * get_protocol(const char * url);
static const char * get_host(const char * url);
static const char * get_uri(const char * url);
static struct field * get_data(const char * url, unsigned int * count);
static struct field * get_params(const char * url, unsigned int * n);
static void free_kv(struct field * data, unsigned int n);
*/
#endif
